home *** CD-ROM | disk | FTP | other *** search
/ Aminet 38 / Aminet 38 (2000)(Schatztruhe)[!][Aug 2000].iso / Aminet / misc / math / libalgo.lha / algomath / src / sumdiv.c < prev    next >
Encoding:
Text File  |  2000-05-30  |  387 b   |  34 lines

  1. /* sum of divisors of n, n not included */
  2. int am_sumdivisors(int n)
  3. {
  4.     int Kleng,x=1;
  5.     int Grouss=n;
  6.     int Sum=n+1;
  7.  
  8.     if(n<0)
  9.         n = -n;
  10.  
  11.     if(n < 2)
  12.         return 0;
  13.  
  14.     if (n&1){
  15.         Kleng=3;
  16.         x=2;
  17.     }
  18.     else
  19.         Kleng=2;
  20.  
  21.     while(Kleng<Grouss)
  22.     {
  23.         if((n % Kleng) == 0)
  24.         {
  25.             Sum += Kleng;
  26.             Grouss = n / Kleng;
  27.             if(Kleng != Grouss)
  28.                 Sum += Grouss;
  29.         }
  30.         Kleng=Kleng+x;
  31.     }
  32.  
  33.     return Sum - n;
  34. }